""""""

"""

1.上课代码敲一遍

2.编写一个函数，在给定整数列表中寻找两个数，它们的和等于给定目标值，
返回这两个数的索引例如给定一个列表[1, 4, 11, 20]，再给定一个数字31，11+20=31，
则返回11和20的索引 

"""


# def find_numbers_index(lists, target):
#     for i in lists:
#         complement = target - i
#         # print(complement)
#         if complement in lists:
#             return lists.index(i)
#             # print(lists.index(i))
#
#
# lists = [1, 4, 11, 20]
# number = 31
#
# res = find_numbers_index(lists, number)
# print(res)

def find_two_sum_indices(nums, target):
    num_dict = {}  # 用于存储数字和其索引的字典
    for i, num in enumerate(nums):
        complement = target - num
        # 检查差值是否在字典中
        print(num_dict)
        if complement in num_dict:
            # 如果找到匹配的数字，返回两个数字的索引
            print(num_dict)
            print(complement)
            print(num_dict[complement])
            print(i)
            # print([num_dict[complement], i])
            # return [num_dict[complement], i]
        # 将当前数字及其索引添加到字典中
        num_dict[num] = i
    # 如果没有找到匹配的数字对，返回空列表
    return []

# 示例用法
nums = [1, 4, 11, 20]
target = 31
result = find_two_sum_indices(nums, target)
# print(result)
